package fileSearchSystem;

import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.Text;

import dbManager.Manager;

/**
 * This class is the model(part of the MVC structure). It uses functions which exist in class Manager 
 */
public class SearchParser 
{
	Manager manager = Manager.getInstance();
	static private SearchParser instance = null;
	//for singleton
	private static Object someObject = new Object();
	
	private SearchParser(){}
	
	static public SearchParser getInstance() 
	{
		if(null == instance) 
		{
			//to insure that the time slice doesn't cause to creation of 2 instances
			synchronized (someObject) 
			{
				if (null == instance)
					instance = new SearchParser();
			}
		}
	    return instance;
	}

	/**
	 * The function call another function which process the query and insert the results to file_text
	 * @param searchString is the query.
	 * @param file_text it the text where the results from the query will be seen
	 */
	public void parseTagString(String searchString, Text file_text) 
	{
		manager.getTheTags(searchString,file_text);
	}
	
	/**
	 * Call a function which truncate the DB tags
	 */
	public void truncate() 
	{
		manager.truncDB();
	}

	/**
	 * Update the table tags with the current DB tags
	 */
	public void update(Table tags)
	{
		manager.getUpdate(tags);
	}

}
